<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>座位号列表</h2>
	</div>
	<form id="CodeForm" action="{:U('createCode')}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">餐桌号</label>
            <div class="controls">
	            <select name="bid">
	                <option value="0" selected="">--请选择餐桌号--</option>
	                <volist name="code_list" id="v">
	                	<option value="{$v.id}" <if condition="$data['bid'] eq $v['id']">selected="selected"</if>>{$v.num}</option>
	                </volist>
	            </select>               
            </div>
        </div>
        <div class="form-item">
        	<input type="hidden" name="id" value="{$data.id|default=0}"/>
            <button class="btn submit-btn" id="submit" type="button" target-form="form-horizontal">生成二维码</button>
        </div>
    </form>
    <div class="showImgs" <if condition="$data['id'] elt 0">style="display:none;"</if>>
    	<img src="{$data.code_url}" alt="{$data.title}">
    </div>
</block>

<block name="script">
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<script type="text/javascript">
	//搜索功能
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".search-input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
    //导航高亮
    highlight_subnav('{:U('Code/index')}');

    $('#submit').click(function(){
    	var url = $('#CodeForm').attr('action');
    	$.post(url, $('#CodeForm').serialize(), function(r){
    		if(r.status){
    			$('.showImgs').show().html('<img src="'+r.code_url+'" />');
    		}else{
    			alert(r.info);
    		}
    	}, 'JSON');
    });
	</script>
</block>
